package com.buaa.daas.schedule;

import com.buaa.daas.service.StuDailyClockMessageService;
import org.apache.tomcat.jni.Time;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Controller;

import java.util.Random;

@Controller
public class AutoBackEndController {

    @Autowired
    private StuDailyClockMessageService stuDailyClockMessageService;

    //cron表达式从左到右（用空格隔开）：秒 分 小时 日期 月份 星期 年份
    //每天下午5点01分触发
    @Scheduled(cron="0 01 17 ? * *")
    void AutoPost(){

        Random random = new Random();
        // 随机延迟180秒
        int randomMinute = random.nextInt(180);
        try {
            Thread.sleep(randomMinute * 1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }


        stuDailyClockMessageService.autoDakaAll();
        System.out.println("定时打卡，定时调度执行成功~");
    }


}
